package cn.bytecollege.controller;

import cn.bytecollege.constant.Resource;
import cn.bytecollege.entity.Page;
import cn.bytecollege.entity.Room;
import cn.bytecollege.service.RoomService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author Mr.H
 */
@WebServlet(name = "RoomListAllController",value = "/roomListAll")
public class RoomListAllController extends HttpServlet {
    private RoomService roomService=null;

    public RoomListAllController(){
        roomService=new RoomService();
    }


    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //接收参数
        String index=request.getParameter("pageIndex");
        String size=request.getParameter("pageSize");
        //封装参数
        Integer pageIndex=(index==null)?1:Integer.valueOf(index);
        Integer pageSize=(size==null)?5:Integer.valueOf(size);
        //调用service方法
        Page<Room> page=roomService.findAllByPage(pageIndex,pageSize);
        //封装结果到请求
        request.setAttribute("page",page);
        request.getRequestDispatcher(Resource.PAGE_LOCATION+"/roomList.jsp").forward(request,response);
    }
}
